package com.gc.web.controller.business;

import java.util.List;
import java.util.Arrays;
import com.gc.common.base.Result;
import com.gc.common.support.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.gc.common.annotation.Log;
import com.gc.common.enums.BusinessType;
import com.gc.business.domain.UpkeepProjectRecord;
import com.gc.business.service.IUpkeepProjectRecordService;
import com.gc.framework.web.base.BaseController;
import com.gc.common.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 电梯保养项目记录 控制层
 * 
 * @author hruiyan
 * @date 2020-11-18
 */
@Slf4j
@Controller
@RequestMapping("/business/upkeepProjectRecord")
public class UpkeepProjectRecordController extends BaseController {
    private String prefix = "business/upkeepProjectRecord";
	
	private final IUpkeepProjectRecordService upkeepProjectRecordService;

	@Autowired
	public UpkeepProjectRecordController(IUpkeepProjectRecordService upkeepProjectRecordService) {
		this.upkeepProjectRecordService = upkeepProjectRecordService;
	}

	/**
	*  列表页
	*/
	@RequiresPermissions("business:upkeepProjectRecord:view")
	@GetMapping
	public String upkeepProjectRecord(){
	    return prefix + "/upkeepProjectRecord";
	}

	/**
	 * 新增页
	 */
	@GetMapping("/add")
	public String add(){
		return prefix + "/add";
	}

	/**
	 * 编辑页
	 */
	@GetMapping("/edit/{recordId}")
	public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap){
		UpkeepProjectRecord upkeepProjectRecord = upkeepProjectRecordService.getById(recordId);
		mmap.put("upkeepProjectRecord", upkeepProjectRecord);
		return prefix + "/edit";
	}
	
	/**
	 * 查询电梯保养项目记录列表
	 */
	@RequiresPermissions("business:upkeepProjectRecord:list")
	@PostMapping("/list")
	@ResponseBody
	public Result list(UpkeepProjectRecord upkeepProjectRecord){
		startPage();
        List<UpkeepProjectRecord> list = upkeepProjectRecordService.list(upkeepProjectRecord);
		return Result.success(getDataTable(list));
	}

	/**
	 * 新增保存电梯保养项目记录
	 */
	@RequiresPermissions("business:upkeepProjectRecord:add")
	@Log(title = "电梯保养项目记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(UpkeepProjectRecord upkeepProjectRecord){
		upkeepProjectRecordService.save(upkeepProjectRecord);
		return Result.success();
	}

	/**
	 * 修改保存电梯保养项目记录
	 */
	@RequiresPermissions("business:upkeepProjectRecord:edit")
	@Log(title = "电梯保养项目记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(UpkeepProjectRecord upkeepProjectRecord){
		upkeepProjectRecordService.updateById(upkeepProjectRecord);
		return Result.success();
	}
	
	/**
	 * 删除电梯保养项目记录
	 */
	@RequiresPermissions("business:upkeepProjectRecord:remove")
	@Log(title = "电梯保养项目记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids){
		Long[] longIds = Convert.toLongArray(ids);
		upkeepProjectRecordService.removeByIds(Arrays.asList(longIds));
		return Result.success();
	}

	/**
	 * 导出电梯保养项目记录列表
	 */
	@RequiresPermissions("business:upkeepProjectRecord:export")
	@PostMapping("/export")
	@ResponseBody
	public Result export(UpkeepProjectRecord upkeepProjectRecord){
		List<UpkeepProjectRecord> list = upkeepProjectRecordService.list(upkeepProjectRecord);
		ExcelUtil<UpkeepProjectRecord> util = new ExcelUtil<>(UpkeepProjectRecord.class);
		util.exportExcel(list, "upkeepProjectRecord");
		return Result.success();
	}
}
